package com.bestcem.xm.ticket.grpc.client.convert;

import cn.hutool.core.collection.CollectionUtil;
import com.bestcem.xm.openplatform.grpc.v1.services.FeiShuEnterpriseInfo;
import com.bestcem.xm.openplatform.grpc.v1.services.FeiShuEnterpriseInfoSearchResponse;
import com.bestcem.xm.ticket.grpc.client.dto.openPlatform.FeiShuEnterpriseInfoDTO;

import java.util.ArrayList;
import java.util.List;

/**
 * Openplatform response 转 DTO
 *
 * @author zq.ding <zq.ding@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/30 20:36
 */
public class TicketBaseOpenPlatformConvert {
    /**
     * response转DTO
     *
     * @param response FeiShuEnterpriseInfoSearch的Response
     * @return 飞书信息DTO列表
     * @author zq.ding <zq.ding@idiaoyan.com>
     * @date 2021/8/31 16:03
     */
    public static List<FeiShuEnterpriseInfoDTO> responseToDTO(FeiShuEnterpriseInfoSearchResponse response) {
        List<FeiShuEnterpriseInfo> infos = response.getFeiShuEnterpriseInfoListList();
        if (CollectionUtil.isEmpty(infos)) {
            return new ArrayList<>();
        }
        List<FeiShuEnterpriseInfoDTO> dtos = new ArrayList<>(infos.size());
        for (FeiShuEnterpriseInfo info : infos) {
            dtos.add(feiShuEnterpriseInfoToDTO(info));
        }
        return dtos;
    }

    /*=================================*/

    /**
     * FeiShuEnterpriseInfo转feiShuEnterpriseInfoDTO
     *
     * @param info grpc传来的info
     * @return com.bestcem.xm.ticket.grpc.client.dto.openPlatform.FeiShuEnterpriseInfoDTO
     * @author zq.ding <zq.ding@idiaoyan.com>
     * @date 2021/8/31 17:19
     */
    private static FeiShuEnterpriseInfoDTO feiShuEnterpriseInfoToDTO(FeiShuEnterpriseInfo info) {
        FeiShuEnterpriseInfoDTO feiShuEnterpriseInfoDTO = new FeiShuEnterpriseInfoDTO();

        feiShuEnterpriseInfoDTO.setId(info.getId());
        feiShuEnterpriseInfoDTO.setOrgCode(info.getOrgCode());
        feiShuEnterpriseInfoDTO.setOrgId(info.getOrgId());
        feiShuEnterpriseInfoDTO.setTenantKey(info.getTenantKey());
        feiShuEnterpriseInfoDTO.setTenantAppid(info.getTenantAppid());
        feiShuEnterpriseInfoDTO.setTenantAppsecret(info.getTenantAppsecret());
        feiShuEnterpriseInfoDTO.setAllowDepartment(info.getAllowDepartmentList());
        feiShuEnterpriseInfoDTO.setAllowUser(info.getAllowUserList());
        feiShuEnterpriseInfoDTO.setAuthUserName(info.getAuthUserName());
        feiShuEnterpriseInfoDTO.setAuthOpenId(info.getAuthOpenId());

        return feiShuEnterpriseInfoDTO;
    }
}
